from rest_framework import serializers

from answers.models import QuesModel
from answers.serializers import AnswersatrrSerializer
from news.models import News, Category, NewsComment
from tucao.models import Tucao
from users.models import User, Dynamics
from users.serializers import DynamicsSerializer


class UserSerializer(serializers.ModelSerializer):
    """用户模型序列化器"""
    class Meta:
        model = User
        fields = ('id','nick_name','avatar_url')
        # fields = "__all__"

class CategorySerializer(serializers.ModelSerializer):
    """分类导航模型序列化器"""
    class Meta:
        model = Category
        fields = '__all__'

# url(r'^news/(?P<pk>\d+)/$', views.NewsCommentView.as_view()),  # 新闻详情评论
class NewsCommentSerializer(serializers.ModelSerializer):
    """新闻评论模型序列化器"""
    class Meta:
        model = NewsComment
        # fields = ["id","content","count","parent"]
        fields = "__all__"


# url(r'^news/$', views.NewsView.as_view()),  # 新闻列表
class NewsSerializer(serializers.ModelSerializer):
    """新闻模型序列化器"""
    user = UserSerializer()
    category = CategorySerializer()
    class Meta:
        model = News
        fields = ["id", "title", "digest", "follow", "disinclination", "category","clicks","create_time", "user"]


class ListTuCaoSerializer(serializers.ModelSerializer):
    """吐槽序列化器"""
    class Meta:
        model = Tucao
        fields = ['id', 'content', 'follow_count']


class NewsQuesSerializer(serializers.ModelSerializer):
    """问答序列化器"""
    qattrModel_set = AnswersatrrSerializer(many=True)
    class Meta:
        model = QuesModel
        fields = ['user', 'title', 'qattrModel_set']



class NewsDetailCommentSerializer(serializers.ModelSerializer):
    """新闻详情加用户加评论序列化器"""
    user = UserSerializer()

    news_comments = NewsCommentSerializer(many=True)
    class Meta:
        model = News
        # fields = "__all__"
        fields = ["id", "title", "content", "collect", "create_time", 'user', 'news_comments']


# class NewsDetailSerializer(serializers.ModelSerializer):
#     """新闻详情序列化器"""
#     user = UserSerializer(read_only=True)
#     class Meta:
#         model = News
#         fields = ["id", "title", "content", "collect", "create_time", 'user']

# class NewsPersonSerializer(serializers.ModelSerializer):
#     """新闻作者序列化器"""
#     news_set = NewsDetailCommentSerializer(many=True)
#     dynamics_set = DynamicsSerializer(many=True)
#     class Meta:
#         model = User
#         fields = "__all__"

